﻿using System;
using System.IdentityModel.Claims;
using System.Web.Security;
using Altairis.IdentityToolkit;

public partial class Login : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e) {

    }

    protected void InfoCardSelector1_TokenSubmitted(object sender, LeastPrivilege.CardSpaceLibrary.UI.TokenSubmittedEventArgs e) {
        // Get card's first ClaimSet
        ClaimSet cs = e.Token.AuthorizationContext.ClaimSets[0];

        // Find membership user name linked to the card
        string userName = IdentityLinkManager.ResolveLink(cs);
        if (string.IsNullOrEmpty(userName)) {
            // No user is assigned - redirect to error page
            Response.Redirect("~/UnlinkedCard.aspx");
        }
        else {
            // Sign in the user using forms authentication
            FormsAuthentication.RedirectFromLoginPage(userName, false);
        }
    }

}
